<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>进货管理</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/main.css">
    <script src="js/jquery-3.5.1.js"></script>
    <script src="js/bootstrap.js"></script>

    <style>
        body {
            background-color: #fde4e4; /* 粉嫩背景色 */
            font-family: 'Arial', sans-serif;
            color: #333;
        }

        .navbar {
            background-color: #fde4e4; /* 导航栏背景色 */
            border: none;
            padding: 10px 0;
        }

        .navbar-brand, .navbar-nav > li > a {
            color: #fff !important; /* 导航栏文字颜色 */
        }

        .navbar-brand:hover, .navbar-nav > li > a:hover {
            color: #ffcccb !important; /* 导航栏文字悬停颜色 */
        }

        .sidebar {
            background: url("img/img_2.png") no-repeat center left; /* 背景图片向右移动 */
            background-size: cover;
            border-right: 1px solid #ffcccb;
            padding: 20px;
            color: #fff; /* 侧边栏文字颜色 */
            margin-right: 40px; /* 左右两部分之间的距离 */
        }

        .main {
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }

        .btn-pill {
            border-radius: 20px;
        }

        .btn-line {
            border: 2px solid #ff6f61;
            background-color: transparent;
            color: #ff6f61;
        }

        .btn-line:hover {
            background-color: #ff6f61;
            color: #fff;
        }

        .btn-danger {
            background-color: #ff6f61;
            border-color: #ff6f61;
        }

        .btn-danger:hover {
            background-color: #ff4c4c;
            border-color: #ff4c4c;
        }

        .table-striped > tbody > tr:nth-of-type(odd) {
            background-color: #fff0f5; /* 表格条纹背景色 */
        }

        .table-hover > tbody > tr:hover {
            background-color: #ffcccb; /* 表格悬停背景色 */
        }

        .modal-content {
            border-radius: 10px;
        }

        .modal-header {
            background-color: #ff6f61;
            color: #fff;
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
        }

        .modal-footer {
            border-bottom-left-radius: 10px;
            border-bottom-right-radius: 10px;
        }

        /* 高级粉感按钮样式 */
        .btn-pink {
            background-color: transparent; /* 背景透明 */
            border: none;
            color: #ff6f61; /* 默认字体颜色 */
            padding: 10px 20px;
            border-radius: 20px;
            font-size: 16px;
            transition: all 0.3s ease;
        }

        .btn-pink:hover {
            color: #ff4c4c; /* 悬停时字体颜色 */
        }

        .btn-pink:active, .btn-pink.active {
            color: #ffcccb; /* 点击或激活时字体颜色 */
        }

        /* 侧边栏按钮样式 */
        .nav-sidebar .btn-pink {
            display: block;
            width: 100%;
            text-align: left;
            margin-bottom: 10px;
        }

        .nav-sidebar .btn-pink.active {
            color: #ffcccb; /* 当前激活按钮的字体颜色 */
        }

        /* 点击按钮时背景色变化 */
        .btn-pink:focus, .btn-pink:active {
            background-color: #ff4c4c; /* 点击时背景色 */
            color: #fff; /* 点击时字体颜色 */
        }
    </style>
</head>

<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">服装店门店信息管理系统</span> <span class="icon-bar"></span>
                <span class="icon-bar"></span> <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">服装店门店信息管理系统</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#">欢迎：<span style="color: yellow">${loginUser.username}</span></a></li>
                <li><a href="AuthServlet?action=logout">退出</a></li>
            </ul>
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <!-- 侧边栏 -->
            <jsp:include page="menu.jsp">
                <jsp:param value="active" name="Jinghuo_active"/>
            </jsp:include>
        </div>
        <br>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="row">
                <div class="col-sm-7">
                    <div class="input-group">
                        <input class="form-control" type="hidden" id="searchColumn" name="searchColumn" value="jinghuo_name"/>
                        <input class="form-control" type="text" id="search_keyword" name="search_keyword" placeholder="商品名称"/> <span class="input-group-btn"><button class="btn btn-pill btn-line btn-danger" type="button" onclick="searchList()">搜索</button></span>
                    </div>
                </div>
                <div class="col-sm-5">
                    <button type="button"
                    <c:if test="${loginUser.userType != '管理员'}">disabled="disabled" title="没有权限！！！"</c:if>
                    class="btn btn-pill btn-line btn-danger" data-toggle="modal" data-target="#modal-add">添加进货</button>
                </div>
            </div>
            <br>
            <br>
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead>
                    <tr>
                            <th>商品名称</th>
                            <th>金额</th>
                            <th>支付方式</th>
                            <th>支付状态</th>
                            <th>数量</th>
                            <th>进货时间</th>
                            <th>商品描述</th>
                        <th style="text-align: center;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${list}" var="vo">
                        <tr>
                <td>${vo.jinghuoName}</td>
                <td>${vo.jinghuoPrice}</td>
                <td>${vo.jinghuoZhifufangshi}</td>
                <td>${vo.jinghuoZhuantai}</td>
                <td>${vo.jinghuoSulinag}</td>
                <td>${vo.jinghuoShijian}</td>
                <td title="${vo.jinghuoText}">
                <c:choose>
                    <c:when test="${fn:length(vo.jinghuoText) > 19}">
                        <c:out value="${fn:substring(vo.jinghuoText, 0, 19)}..."/>
                    </c:when>
                    <c:otherwise>
                        <c:out value="${vo.jinghuoText}"/>
                    </c:otherwise>
                </c:choose>
                </td>
                            <th style="text-align: center;">
                                <button class="btn btn-pill btn-line btn-warning btn-sm" data-id="${vo.id}"
                                        data-toggle="modal" data-target="#modal-info">详情
                                </button>
                                <button class="btn btn-pill btn-line btn-info btn-sm"
                                                <c:if test="${loginUser.userType != '管理员'}">disabled="disabled" title="没有权限！！！"</c:if>
                                        data-id="${vo.id}"
                                        data-toggle="modal" data-target="#modal-edit">编辑
                                </button>
                                <button class="btn btn-pill btn-line btn-info btn-sm"
                                <c:if test="${loginUser.userType != '管理员'}">disabled="disabled" title="没有权限！！！"</c:if>
                                data-id="${vo.id}" data-toggle="modal" data-target="#modal-delete">删除
                                </button>
                            </th>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
            <div style="float: right;padding-right: 10px;color: #515151;"><jsp:include page="split.jsp"/></div>
        </div>
    </div>
</div>

<!-- add -->
<div class="modal fade" id="modal-add" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form action="JinghuoServlet" onsubmit="return addCheck()">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">增加进货</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group hidden">
                        <label class="control-label">(hidden)</label>
                        <input type="text" class="form-control" name="action" value="add">
                    </div>
                    <div class="form-group">
                        <label for="add-jinghuoName" class="control-label">商品名称:</label>
                        <input type="text" class="form-control" name="jinghuoName" id="add-jinghuoName">
                    </div>
                    <div class="form-group">
                        <label for="add-jinghuoPrice" class="control-label">金额:</label>
                        <input type="text" class="form-control" name="jinghuoPrice" id="add-jinghuoPrice">
                    </div>
                    <div class="form-group">
                        <label class="control-label">支付方式:</label>
                        <input name="jinghuoZhifufangshi" id="add-jinghuoZhifufangshi_现金" type="radio" value="现金" checked="checked"/>现金
                        <input name="jinghuoZhifufangshi" id="add-jinghuoZhifufangshi_转帐" type="radio" value="转帐"/>转帐
                    </div>
                    <div class="form-group">
                        <label class="control-label">支付状态:</label>
                        <input name="jinghuoZhuantai" id="add-jinghuoZhuantai_已支付" type="radio" value="已支付" checked="checked"/>已支付
                        <input name="jinghuoZhuantai" id="add-jinghuoZhuantai_未支付" type="radio" value="未支付"/>未支付
                    </div>
                    <div class="form-group">
                        <label for="add-jinghuoSulinag" class="control-label">数量:</label>
                        <input type="text" class="form-control" name="jinghuoSulinag" id="add-jinghuoSulinag">
                    </div>
                    <div class="form-group">
                        <label for="add-jinghuoShijian" class="control-label">进货时间:</label>
                        <input type="text" class="form-control" name="jinghuoShijian" id="add-jinghuoShijian">
                    </div>
                    <div class="form-group">
                        <label for="add-jinghuoText" class="control-label">商品描述:</label>
                        <textarea style="height: 100px;" class="form-control" name="jinghuoText" id="add-jinghuoText"></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-pill btn-line btn-info" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-pill btn-line btn-danger">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- info -->
<div class="modal fade" id="modal-info" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form>
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title">进货</h4>
                </div>
                <div class="modal-body">
                    <table class="table table-striped table-hover" style="font-size: 15px;">
                        <tr>
                            <td style="width: 15%;">商品名称:</td>
                            <td><b id="info-jinghuoName"></b></td>
                        </tr>
                        <tr>
                            <td style="width: 15%;">金额:</td>
                            <td><b id="info-jinghuoPrice"></b></td>
                        </tr>
                        <tr>
                            <td style="width: 15%;">支付方式:</td>
                            <td><b id="info-jinghuoZhifufangshi"></b></td>
                        </tr>
                        <tr>
                            <td style="width: 15%;">支付状态:</td>
                            <td><b id="info-jinghuoZhuantai"></b></td>
                        </tr>
                        <tr>
                            <td style="width: 15%;">数量:</td>
                            <td><b id="info-jinghuoSulinag"></b></td>
                        </tr>
                        <tr>
                            <td style="width: 15%;">进货时间:</td>
                            <td><b id="info-jinghuoShijian"></b></td>
                        </tr>
                        <tr>
                            <td style="width: 15%;">商品描述:</td>
                            <td><b id="info-jinghuoText"></b></td>
                        </tr>
                    </table>
                    <br>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-pill btn-line btn-info" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- edit -->
<div class="modal fade" id="modal-edit" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form action="JinghuoServlet" onsubmit="return editCheck()">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title">更新进货</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group hidden">
                        <label class="control-label">(hidden)</label>
                        <input type="text" class="form-control" name="action" value="edit">
                        <input type="text" readonly class="form-control" name="id" id="edit-id">
                        <input type="text" readonly class="form-control" name="createBy" id="edit-createBy">
                    </div>
                    <div class="form-group">
                        <label for="edit-jinghuoName" class="control-label">商品名称:</label>
                        <input type="text" class="form-control" name="jinghuoName" id="edit-jinghuoName">
                    </div>
                    <div class="form-group">
                        <label for="edit-jinghuoPrice" class="control-label">金额:</label>
                        <input type="text" class="form-control" name="jinghuoPrice" id="edit-jinghuoPrice">
                    </div>
                    <div class="form-group">
                        <label class="control-label">支付方式:</label>
                               <input name="jinghuoZhifufangshi" id="edit-jinghuoZhifufangshi_现金" type="radio" value="现金"/>现金
                               <input name="jinghuoZhifufangshi" id="edit-jinghuoZhifufangshi_转帐" type="radio" value="转帐"/>转帐
                    </div>
                    <div class="form-group">
                        <label class="control-label">支付状态:</label>
                               <input name="jinghuoZhuantai" id="edit-jinghuoZhuantai_已支付" type="radio" value="已支付"/>已支付
                               <input name="jinghuoZhuantai" id="edit-jinghuoZhuantai_未支付" type="radio" value="未支付"/>未支付
                    </div>
                    <div class="form-group">
                        <label for="edit-jinghuoSulinag" class="control-label">数量:</label>
                        <input type="text" class="form-control" name="jinghuoSulinag" id="edit-jinghuoSulinag">
                    </div>
                    <div class="form-group">
                        <label for="edit-jinghuoShijian" class="control-label">进货时间:</label>
                        <input type="text" class="form-control" name="jinghuoShijian" id="edit-jinghuoShijian">
                    </div>
                    <div class="form-group">
                        <label for="edit-jinghuoText" class="control-label">商品描述:</label>
                        <textarea style="height: 100px;" class="form-control" name="jinghuoText" id="edit-jinghuoText"></textarea>
                    </div>
                    <div class="form-group hidden">
                        <label for="edit-createTime" class="control-label">创建时间:</label>
                        <input type="text" class="form-control" name="createTime" id="edit-createTime">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-pill btn-line btn-info" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-pill btn-line btn-danger">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- delete -->
<div class="modal fade" id="modal-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form action="JinghuoServlet">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title">删除进货</h4>
                </div>
                <div class="modal-body">
                    确认要删除该进货记录吗？
                    <div class="form-group hidden">
                        <label class="control-label">(hidden)</label>
                        <input type="hidden" class="form-control" name="action" value="delete">
                        <input type="text" class="form-control" name="id" id="delete-id">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-pill btn-line btn-info" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-pill btn-line btn-info">删除</button>
                </div>
            </form>
        </div>
    </div>
</div>

</body>
<script>
    $('#modal-delete').on('show.bs.modal', function (event) {
        let button = $(event.relatedTarget);
        let id = button.data('id');
        let modal = $(this);
        modal.find('#delete-id').val(id);
    })

    $('#modal-edit').on('show.bs.modal', function (event) {
        let button = $(event.relatedTarget);
        let id = button.data('id');
        let modal = $(this);
        $.ajax({
            url: 'JinghuoServlet?action=get&id=' + id,
            type: "get",
            success: function (voString) {
                let vo = eval('(' + voString + ')');
                        modal.find('#edit-id').val(vo.id);
                        modal.find('#edit-jinghuoName').val(vo.jinghuoName);
                        modal.find('#edit-jinghuoPrice').val(vo.jinghuoPrice);
                        for (let val of "现金/转帐".split('/')) {
                            if (val == vo.jinghuoZhifufangshi) {
                                modal.find('#edit-jinghuoZhifufangshi_' + vo.jinghuoZhifufangshi).prop("checked", true);
                            } else {
                                modal.find('#edit-jinghuoZhifufangshi_' + vo.jinghuoZhifufangshi).removeAttr("checked");
                            }
                        };
                        for (let val of "已支付/未支付".split('/')) {
                            if (val == vo.jinghuoZhuantai) {
                                modal.find('#edit-jinghuoZhuantai_' + vo.jinghuoZhuantai).prop("checked", true);
                            } else {
                                modal.find('#edit-jinghuoZhuantai_' + vo.jinghuoZhuantai).removeAttr("checked");
                            }
                        };
                        modal.find('#edit-jinghuoSulinag').val(vo.jinghuoSulinag);
                        modal.find('#edit-jinghuoShijian').val(vo.jinghuoShijian);
                        modal.find('#edit-jinghuoText').val(vo.jinghuoText);
                        modal.find('#edit-createBy').val(vo.createBy);
            }
        })
    })
    $('#modal-info').on('show.bs.modal', function (event) {
        let button = $(event.relatedTarget);
        let id = button.data('id');
        let modal = $(this);
        $.ajax({
            url: 'JinghuoServlet?action=get&id=' + id,
            type: "get",
            success: function (voString) {
                let vo = eval('(' + voString + ')');
                modal.find('#info-jinghuoName').text(vo.jinghuoName);
                modal.find('#info-jinghuoPrice').text(vo.jinghuoPrice);
                modal.find('#info-jinghuoZhifufangshi').text(vo.jinghuoZhifufangshi);
                modal.find('#info-jinghuoZhuantai').text(vo.jinghuoZhuantai);
                modal.find('#info-jinghuoSulinag').text(vo.jinghuoSulinag);
                modal.find('#info-jinghuoShijian').text(vo.jinghuoShijian);
                modal.find('#info-jinghuoText').text(vo.jinghuoText);
                modal.find('#info-createBy').text(vo.createBy);
            }
        })
    })
    function searchList() {
        window.location.href = "JinghuoServlet?action=list&searchColumn="+document.getElementById("searchColumn").value+"&keyword=" + document.getElementById("search_keyword").value;
    }
    //增加表单提交之前进行检查，如果return false，则不允许提交
    function addCheck() {
        //根据ID获取值
        if (document.getElementById("add-jinghuoName").value.trim().length == 0) {
            alert("商品名称不能为空");
            return false;
        }
        if (document.getElementById("add-jinghuoPrice").value.trim().length == 0) {
            alert("金额不能为空");
            return false;
        }
        if (document.getElementById("add-jinghuoSulinag").value.trim().length == 0) {
            alert("数量不能为空");
            return false;
        }
        if (document.getElementById("add-jinghuoShijian").value.trim().length == 0) {
            alert("进货时间不能为空");
            return false;
        }
        return true;
    }
    //编辑表单提交之前进行检查，如果return false，则不允许提交
    function editCheck() {
        //根据ID获取值
        if (document.getElementById("edit-jinghuoName").value.trim().length == 0) {
            alert("商品名称不能为空");
            return false;
        }
        if (document.getElementById("edit-jinghuoPrice").value.trim().length == 0) {
            alert("金额不能为空");
            return false;
        }
        if (document.getElementById("edit-jinghuoSulinag").value.trim().length == 0) {
            alert("数量不能为空");
            return false;
        }
        if (document.getElementById("edit-jinghuoShijian").value.trim().length == 0) {
            alert("进货时间不能为空");
            return false;
        }
        return true;
    }
</script>
</html>
